﻿using MaterialDesignThemes.Wpf;
using Minotaur.App.Core;
using Minotaur.App.Core.Mvvm;
using Minotaur.App.Core.Redis;
using Minotaur.App.Domains.Dto;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace Minotaur.App.Modules.Home.ViewModels
{
    public class HomeViewModel : WindowComputeViewModel
    {
        private string _message;
        public string Message
        {
            get { return _message; }
            set { SetProperty(ref _message, value); }
        }
        private GlobalUserModel _GlobalUserModel;
        /// <summary>
        /// 员工信息数据
        /// </summary>
        public GlobalUserModel GlobalUserModel { get => globalUserModel; set => SetProperty(ref globalUserModel, value); }
        public TabControl tabControl { get; set; }
        public ListBox flowTypeView { get; set; }

        public ScrollViewer AnnouncementCotrl { get; set; }

        /// <summary>
        /// 公告数据
        /// </summary>
        public ObservableCollection<AnnouncementDto> AnnouncementDtos { get => announcementDtos; set => SetProperty(ref announcementDtos, value); }
        public ObservableCollection<HomeFlowListDto> HomeFlowListDto { get => homeFlowListDto; set => SetProperty(ref homeFlowListDto, value); }
        public ObservableCollection<FlowTypeDto> FlowTypeDtos { get => flowTypeDtos; set => SetProperty(ref flowTypeDtos, value); }

        private GlobalUserModel globalUserModel;

        private ObservableCollection<AnnouncementDto> announcementDtos = new ObservableCollection<AnnouncementDto>();
        private ObservableCollection<HomeFlowListDto> homeFlowListDto = new ObservableCollection<HomeFlowListDto>();
        private ObservableCollection<FlowTypeDto> flowTypeDtos = new ObservableCollection<FlowTypeDto>();

        public HomeViewModel(IRegionManager regionManager, IDbContext dbContext, GlobalUserModel globalUserModel, IRedisClient redisClient) : base(regionManager, dbContext, redisClient)
        {
            GlobalUserModel = globalUserModel;
            for (int i = 1; i <= 16; i++)
            {
                AnnouncementDtos.Add(new AnnouncementDto()
                {
                    PackIconKind = MaterialDesignThemes.Wpf.PackIconKind.MessageReplyText,
                    ID = i,
                    Name = $"公司的测试通知公告({i})",
                    ReceptionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                });
            }

            HomeFlowListDto homeFlow = new HomeFlowListDto()
            {
                TaskDtos = new ObservableCollection<FlowTaskDto>(),
                Title = "待办审批",
            };
            HomeFlowListDto applyFlow = new HomeFlowListDto()
            {
                TaskDtos = new ObservableCollection<FlowTaskDto>(),
                Title = "待办申请",
            };
            HomeFlowListDto approvedFlow = new HomeFlowListDto()
            {
                TaskDtos = new ObservableCollection<FlowTaskDto>(),
                Title = "已办事项",
            };
            for (int i = 1; i <= 15; i++)
            {
                FlowTaskDto flowTaskDto = new FlowTaskDto()
                {
                    FlowId = 1000 + i,
                    FlowStatus = "处理中",
                    GroupId = 10000 + i,
                    InstanceId = i,
                    TaskId = i + 100,
                    TaskStatus = "待审批",
                    TaskTitle = $"待办任务{i}",
                    Type = "综合流程",
                    PackIconKind = PackIconKind.SitemapOutline
                };
                homeFlow.TaskDtos.Add(flowTaskDto);
                applyFlow.TaskDtos.Add(flowTaskDto);
                approvedFlow.TaskDtos.Add(flowTaskDto);
            }
            this.HomeFlowListDto.Add(homeFlow);
            this.HomeFlowListDto.Add(applyFlow);
            this.HomeFlowListDto.Add(approvedFlow);
            for (int i = 1; i <= 10; i++)
            {
                this.flowTypeDtos.Add(new FlowTypeDto()
                {
                    FlowId = 1000 + i,
                    PackIconKind = (PackIconKind)(100 + i),
                    Title = $"流程分类({i})",
                    Type = "综合流程",
                    Color = $"#f25e{(i < 10 ? "0" + 1 : i)}"

                });
            }
        } 

        public override void InitData()
        { 
        }
    }
}
